package com.kaifamiao.date;

import java.util.Date;

/**
 * 1、比较Date实例是否“相等”
 *      boolean equals( Object )
 * 2、比较Date实例的“大小”
 *      int compareTo( Date another )
 * 3、比较Date实例所表示时间的早晚
 *      boolean before( Date another ): 当 this 比 another 早则返回 true
 *      boolean after( Date another ) : 当 this 比 another 晚则返回 true
 */
public class DateCompare {

    public static void main(String[] args) {

        final long millis = System.currentTimeMillis();

        Date first = new Date( millis );
        Date second = new Date( millis );

        System.out.println( first == second ); // false
        System.out.println( first.equals( second ) ); // true
        System.out.println( first.compareTo( second ) ); // 0
        System.out.println( second.compareTo( first ) ); // 0

        Date third = new Date( millis + 1000L * 60 * 60 * 24 );
        System.out.println( first.compareTo( third ) ); // 负整数
        System.out.println( third.compareTo( first ) ); // 正整数

        System.out.println( first.before( third ) ); // true
        System.out.println( first.after( third ) ); // false

        System.out.println( third.before( first ) ); // false
        System.out.println( third.after( first ) ); // true

    }

}
